'aburendercomponent.monkey by Belimoth
Strict
Import mojo
Import abuframework		'not sure this is good
Import abuentity



Interface IRenderable
	Method Render:Void()
End



Interface IRender Extends IRenderable
	Method Visible:Bool() Property
	Method Visible:Void(visible:Bool) Property
	Method Alpha:Float() Property
	Method Alpha:Void(alpha:Float) Property
	Method ZIndex:Int() Property
	Method ZIndex:Void(zIndex:Int) Property
	'Method StartFlicker:Void(duration:Int = -1, rate:Int = -1, fillColor:Int = -1)					'decide on a default rate
	'Method StopFlicker:Void()
	'Method IsFlickering:Bool()
	'Method CameraFilter:List<AbuCamera>() Property		'read-only but you just do CameraFilter().AddLast(myCamera) to change it anyways		'NOTE: be sure to initialize this
	'Method IsOnScreen:Bool(camera:AbuCamera = Null)
End



Class AbuRenderObject Implements IRender
	Method New(owner:IRenderable)
		_owner = owner	
	End
	
	Method Visible:Bool() Property Return _visible End
	Method Visible:Void(visible:Bool) Property _visible = visible End
	Method Alpha:Float() Property Return _alpha End
	Method Alpha:Void(alpha:Float) Property _alpha = alpha End
	Method ZIndex:Int() Property Return _zIndex End
	Method ZIndex:Void(zIndex:Int) Property _zIndex = zIndex End
	
	Method Render:Void()
		SetAlpha _alpha
		_owner.Render()
	End
	
Private
	Field _owner:IRenderable
	
	Field _visible:Bool = True
	Field _alpha:Float = 1
	Field _zIndex:Int
End



Class RenderComponent Extends EntityComponent Implements IRender

Public
	Method Visible:Bool() Property Return _visible End
	Method Visible:Void(visible:Bool) Property _visible = visible End
	Method Alpha:Float() Property Return _alpha End
	Method Alpha:Void(alpha:Float) Property _alpha = alpha End
	Method ZIndex:Int() Property Return _zIndex End
	Method ZIndex:Void(zIndex:Int) Property
		'TODO not sure if this has been tested
		If _linkStage <> Null
			_linkStage.Remove()
		EndIf
		_linkStage = Abu.stage.Add(Self)
		_zIndex = zIndex
	End
		
	Method Render:Void()
		SetAlpha _alpha
		owner.Render()
		SetAlpha 1
	End
	
Private
	Field _visible:Bool = True
	Field _alpha:Float = 1
	Field _zIndex:Int
	
	Field _linkStage:list.Node<IRender>
End



#Rem
Class ShapeRender Extends RenderComponent
	Method Render:Void()
		DrawRect(owner.X, owner.Y, owner.Width, owner.Height)
	End
End
#End



Class SpriteRender Extends RenderComponent

Public	
	Method Render:Void()
		Local alphaTemp:Float = GetAlpha()
		SetAlpha(_alpha)
		owner.SpriteComponent.Draw(owner.PositionComponent.X, owner.PositionComponent.Y)
		SetAlpha(alphaTemp)
	End
	
	#Rem
	Method StartFlicker:Void(duration:Int = -1, rate:Int = -1, fillColor:Int = -1)
		'TODO
	End
	
	Method StopFlicker:Void()
		'TODO stop flicker effect, if it is in an off cycle then wait until the next on cycle
	End
	
	Method IsFlickering:Bool()
		Return flickering
	End
	#End
	
Private
	Field flickering:Bool	
End